<?php
class News extends FrontAction{
	function index($pagenow,$pagesize){
		
		$lang = getlang();
		$db = $this->getDB();		
		
		require loadinc('front_pagesplit');
		
		$rownums = $db->get_assoc("select count(*) as rownums from news where lang = '".$this->lang."' ");
		$rownums = $rownums['rownums'];
		
		$pagesplit = new PageSplit();
		$pagecount = $pagesplit->getPageCount($pagesize,$rownums);
		$start = $pagesplit->getStart($pagesize,$pagenow);
		
		$news = $db->query_assoc("select DISTINCT(new.id) id,new.*,nimg.imgurl from news new left join news_images nimg on new.id = nimg.newsid  where new.lang = '".$this->lang."' GROUP BY new.id  limit ".$start.",".$pagesize);
		$links = "/index.php/news/index";
		$pagebar = $pagesplit->getPageBar($links,$pagenow,$pagesize,$pagecount,$this->lang);
		
		$topnews = $db->query_assoc("select * from news where lang = '".$this->lang."'  order by createtime desc limit 0,20");
		$this->data['topnews'] = $topnews; 
		
		$this->data['pagebar'] = $pagebar;
		$this->data['news']=$news;
		
		template('news',$this->data);
	}
	
	function show($nid){
		
		$db = $this->getDB();	
		
		$news = $db->get_assoc("select * from news where id = $nid");
		$this->data['news'] = $news;
		
		$topnews = $db->query_assoc("select * from news where lang = '".$this->lang."'  order by createtime desc limit 0,20");
		$this->data['topnews'] = $topnews; 
		
		template('news_show',$this->data);
	}
	
}